AGB FAQ, GNU

FAQ MENU

## GNU

[Q001] Variables declared 8bit, 16bit end up being 4 bytes in size!
[Q002] Can I change the value of a global variable after declaring it with an initial value?
[Q003] Are there documents and a manual relating to the in-line assembler?
[Q004] When I use the C library function rand() the same value gets returned every time!
[Q005] When I look at the MAP file it looks like the debug information is still there.
[Q006] The LDRH command has an unexpected outcome.
[Q007] When I include and use char-type odd sized arrays, the subsequent data is out of alignment. How do you specify alignment with C?

### [Q001]

Variables declared 8bit, 16bit end up being 4 bytes in size!

### [A001]

Specify the -fno-common option when you compile.
But note that because the COMMON section is moved to the .bss region, even an array of elements of less than 2 bytes is aligned in element units.

[TOP]

### [Q002]

Can I change the value of a global variable after declaring it with an initial value?

### [A002]

Normally you should declare global variables uninitialized, and explicitly initialize them in the program.
When you use a linker script, you can utilize the symbols that the linker creates.

[TOP]

### [Q003]

Are there documents and a manual relating to the in-line assembler?

### [A003]

Refer to the "GNUPro Toolkit" manual included in the AGB Developer ToolKit.

[TOP]

### [Q004]

When I use the C library function rand() the same value gets returned every time!

### [A004]

It appears that an initialized variable (data section) is being used inside the rand() function. Because the data section is mapped to ROM by default, nothing can be written to the variable and the same value is returned.
In order to obtain the intended result, use a linker script and map the data section to RAM. It would be worthwhile taking a look at the sample [overlay], contained in your AGB Developer ToolKit .

[TOP]

### [Q005]

When I look at the MAP file it looks like the debug information is still there.

### [A005]

The debug_*** section that is output at the time of linking is a section that exists only in the elf file and is debug information used by the debugger. This information is completely deleted when objcopy performs the conversion from the elf file to the bin file. Therefore, it has absolutely no effect on the size of ROM.

[TOP]

### [Q006]

The LDRH command has an unexpected outcome.

### [A006]

You might be making half-word access to an odd address. Set things so that your half-word access does not straddle a 2byte boundary. For details, please read Chapter 3, of the ARM manual (3.10 Load and Store Halfword and Load Signed Byte Instructions).

[TOP]

### [Q007]

When I include and use char-type odd sized arrays, the subsequent data is not aligned. How do you specify alignment with C?

### [A007]

Basically, you do this by adjusting the size of the array. Though not a normal practice for C, you can also do this by using the GNU C extended character method.
const char data[0x10] _attribute_ ((aligned (4))) ={0,1,2,3,...};

[TOP]

D.C.N. AGB-06-0027-001A1 (2/21/01)
© 2001 Nintendo of America Inc.